<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:replace="admin/head :: head"></div>

    <title>菜单表单</title>
</head>
<body>
<div class="x-body layui-anim layui-anim-up">
    <form class="layui-form" th:object="${menu}">
        <input type="hidden" name="id" value=""/>

        <div class="layui-form-item">
            <label for="L_name" class="layui-form-label">
                菜单名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_name" name="name" required="" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_url" class="layui-form-label">
                URL
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_url" name="url" required="" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_parent" class="layui-form-label">
                上级菜单
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_parent" name="parent" required="" lay-verify="number" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_icon" class="layui-form-label">
                菜单图标
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_icon" name="icon" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_description" class="layui-form-label">
                菜单描述
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_description" name="description" required="" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_visible" class="layui-form-label">
                是否可见
            </label>
            <div class="layui-input-inline">
                <select name="visible" class="layui-input" id="L_visible" required="" lay-verify="required">
                    <option value="1">是</option>
                    <option value="0">否</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_level" class="layui-form-label">
                菜单层级
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_level" name="level" required="" lay-verify="number" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_order" class="layui-form-label">
                菜单排序
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_order" name="order" required="" lay-verify="number" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <button class="layui-btn" lay-filter="add" lay-submit="">
                增加
            </button>
        </div>
    </form>
</div>

<script>
    layui.use(['form', 'layer', 'upload'], function(){
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload;

        //自定义验证规则
        form.verify({

        });

        //监听提交
        form.on('submit(add)', function(data){
            $.ajax({
                type: 'post',
                url: '/admin/permission/menu/save',
                data: data.field,
                dataType: 'json',
                beforeSend : function(xhr) {
                    xhr.setRequestHeader($("meta[name='_csrf_header']").attr("content"), $("meta[name='_csrf']").attr("content"));
                },
                success: function(result) {
                    if(result.status == 200) {
                        layer.alert(Messages.SUCCESS, {icon: 6}, function () {
                            // get frame index
                            var index = parent.layer.getFrameIndex(window.name);
                            // refresh parent list and close current dialog
                            parent.location.reload();
                            parent.layer.close(index);
                        });
                    } else {
                        layer.alert(result.error == null || result.error == undefined ? Messages.ERROR : result.error, {icon: 1});
                        return false;
                    }
                },
                error: function(e) {
                    layer.alert(Messages.ERROR, {icon: 1});
                }
            })
            return false;
        });


    });
</script>

</body>
</html>